/*
 * Author: vyouzhi <vyouzhi@163.com>
 * http://www.xda.cn
 *
 * File: common_fun.c
 * Create Date: 2012-03-02 09:52:24
 *
 */

#include "common_fun.h"

bool fileExists(const char *filename){
	return access(filename, 0) == 0;
}

bool isDir(const char *filename){
	struct stat buf;
	if (stat(filename, &buf) != 0){
		return false;
	}

	return S_ISDIR(buf.st_mode);
}

bool isFile(const char *filename){
	struct stat buf;
	if (stat(filename, &buf) != 0){
		return false;
	}

	return S_ISREG(buf.st_mode);
}

void chopPath(char *filePath){
	int lastIndex;
	if (*filePath == '\0'){
		return;
	}

	lastIndex = strlen(filePath) - 1;
	if (filePath[lastIndex] == '/'){
		filePath[lastIndex] = '\0';
	}
}

/* vim: set ts=4 sw=4: */

